/*
 * @Description: 
 * @version: 1.0
 * @Author: ziwei
 * @Date: 2021-08-29 14:29:46
 * @LastEditors: ziwei
 * @LastEditTime: 2021-08-29 17:06:04
 */
const {
    fstat
} = require('fs');
let {
    SyncHook
} = require('tapable');
// Compiler就是个编译大管家
//负责整个
class Compiler {
    constructor(options) {
        this.options = options;
        this.hooks = {
            run: new SyncHook(), //会在编译时触发
            done: new SyncHook(), //会在结束编译时触发
        }
    }
    //4.执行Compiler对象的run方法开始编译
    run(callback) {
        this.hooks.run.call();
        //5.根据配置中的entry找出入口文件
        this.compiler((err, stats) => {
            for (let filename in stats) {
                let filePath = path.join(this.options.output, filename)
                fs.writeFileSync(filePath, stats.assets[filename], 'utf8')
            }
            callback()
        })
        this.hooks.done.call();
        //获取每个文件的入口文件
        Object.values(this.options.entry).forEach(entry => {
            fs.watchFile(entry, () => this.compile(callback))
        })
    }
    compile(callback) {
        //每次编译都会创建一个新的complicaiton
        let complication = new
    }
}
module.exports = Compiler